<template>
	<view class="content">
		<uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="info" :current="current" :mode="mode"
					:dots-styles="dotsStyles" field="content">
					<swiper class="swiper-box" @change="change" :current="swiperDotIndex" autoplay="true">
						<swiper-item v-for="(item, index) in info" :key="index">
							<view class="swiper-item" :class="'swiper-item' + index">
								<image :src="item.url"></image>
							</view>
						</swiper-item>
					</swiper>
				</uni-swiper-dot>
				<view style="margin: 50rpx;">
				美好的生活，让我们需要记录点什么！
				</view>
				<view>
					<view class="all">
							<!-- 写死的头像 -->
							<image :src="avatar" style="width: 200rpx;height: 200rpx; margin-top: 30rpx;" ></image>
							<!-- 用户名 -->
							<view style="margin-top: 30rpx;">{{    userinfo.nickname==null? " ": userinfo.nickname+",您好！"}}</view>
							<!-- 登录/注册/退出 -->
							<view class="cli" style="margin-top: 30rpx;margin-bottom: 30rpx;">
								<button v-show="userinfo.username == '您好，请先登录'" class="mini-btn cli_a" @click="login()" type="primary" size="mini">登录</button>
								<button class="mini-btn cli_b" @click="register()" type="primary" size="mini">注册新账号</button>
								<button class="mini-btn cli_c" @click="upme()" type="primary" size="mini">修改个人信息</button>
								<button class="mini-btn cli_c" @click="exit()" type="primary" size="mini">退出本账号</button>
						</view>

					</view>
					
				
				</view>
	</view>
</template>

<script>
	import bill from '../../api/pay.js';
	export default {
		data() {
			return {
				avatar: '../../static/pic/ji.webp',
				userinfo: {
					
					username: '您好，请先登录'
				},
				info: [{
						colorClass: 'uni-bg-red',
						url: 'https://img2.baidu.com/it/u=3157163276,156538027&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=447',
						content: '内容 A'
					},
					{
						colorClass: 'uni-bg-green',
						url: 'https://img0.baidu.com/it/u=4177357759,1287187490&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=312',
						content: '内容 B'
					},
					{
						colorClass: 'uni-bg-blue',
						url: 'https://img1.baidu.com/it/u=2587832827,4000221591&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
						content: '内容 C'
					}
				],
				dotStyle: [{
						backgroundColor: 'rgba(0, 0, 0, .3)',
						border: '1px rgba(0, 0, 0, .3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(0, 0, 0, .9)',
						selectedBorder: '1px rgba(0, 0, 0, .9) solid'
					},
					{
						backgroundColor: 'rgba(255, 90, 95,0.3)',
						border: '1px rgba(255, 90, 95,0.3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',
						selectedBorder: '1px rgba(255, 90, 95,0.9) solid'
					},
					{
						backgroundColor: 'rgba(83, 200, 249,0.3)',
						border: '1px rgba(83, 200, 249,0.3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',
						selectedBorder: '1px rgba(83, 200, 249,0.9) solid'
					}
				],
				modeIndex: -1,
				styleIndex: -1,
				current: 0,
				mode: 'default',
				dotsStyles: {},
				swiperDotIndex: 0
			}
		},
		onLoad() {
			this.getUser();
		},
		methods: {
			upme(){
				uni.navigateTo({
					url:'/pages/upme/upme?id='+this.userinfo.id
				})
			},
			change(e) {
				this.current = e.detail.current
			},
			selectStyle(index) {
				this.dotsStyles = this.dotStyle[index]
				this.styleIndex = index
			},
			selectMode(mode, index) {
				this.mode = mode
				this.modeIndex = index
				this.styleIndex = -1
				this.dotsStyles = this.dotStyle[0]
			},
			clickItem(e) {
				this.swiperDotIndex = e
			},
			onBanner(index) {
				console.log(22222, index);
			},
			// 登录
				login() {
					uni.redirectTo({
						url: '/pages/login/login'
					});
				},
				// 注册
				register() {
					uni.navigateTo({
						url: '/pages/register/register'
					});
				},
				// 退出登录，清空token
				exit() {
					uni.removeStorage({
						key: 'token',
						success(res) {
							uni.redirectTo({
								url: '/pages/login/login'
							});
						}
					});
				},
				// 拿着token找用户信息
				getUser() {
					try {
						const value = uni.getStorageSync('token');
						if (!value) {
							uni.redirectTo({
								url: '/pages/login/login'
							});
						} else {
							bill.getUserInfoByToken().then(res => {
								this.userinfo = res.data.data.userInfo;
			
							});
						}
					} catch (e) {
						// error
					}
				}
			},
	}
</script>


<style lang="scss">
	.all {
		border: 10px #d5ebe1 solid;
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-direction: column;
	
		.cli {
			display: flex;
			justify-content: space-around;
			align-items: center;
			.cli_a,
			.cli_b,
			.cli_c {
				margin: 10rpx;
			}
		}
	}
	.swiper-box {
		height: 200px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 200px;
		color: #fff;
	}

	.swiper-item0 {
		background-color: #cee1fd;
	}

	.swiper-item1 {
		background-color: #b2cef7;
	}

	.swiper-item2 {
		background-color: #cee1fd;
	}

	.image {
		width: 750rpx;
	}

	/* #ifndef APP-NVUE */
	::v-deep .image img {
		-webkit-user-drag: none;
		-khtml-user-drag: none;
		-moz-user-drag: none;
		-o-user-drag: none;
		user-drag: none;
	}

	/* #endif */

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			margin: 0 auto;
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}

	.uni-bg-red {
		background-color: #ff5a5f;
	}

	.uni-bg-green {
		background-color: #09bb07;
	}

	.uni-bg-blue {
		background-color: #007aff;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 20rpx;
	}

	.example-body-item {

		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin: 15rpx;
		padding: 15rpx;
		height: 60rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		padding: 0 15rpx;
		/* #endif */
		flex: 1;
		border-color: #e5e5e5;
		border-style: solid;
		border-width: 1px;
		border-radius: 5px;
	}

	.example-body-item-text {
		font-size: 28rpx;
		color: #333;
	}

	.example-body-dots {
		width: 16rpx;
		height: 16rpx;
		border-radius: 50px;
		background-color: #333333;
		margin-left: 10rpx;
	}

	.active {
		border-style: solid;
		border-color: #007aff;
		border-width: 1px;
	}
</style>


